package com.pig.service.Impl;

import com.pig.mapper.UserMapper;
import com.pig.pojo.User;
import com.pig.service.UserService;
import com.pig.util.SysResultLayui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    /**分页查询用户信息
     * @return*/

    @Override
    public SysResultLayui<User> findUserByPage(int page, int limit) {
        long total = userMapper.selectCount(null);
        int startIndex = (page-1)*limit;
        int count = userMapper.selectCount(null);
        List<User> itemList = userMapper.findUserByPage(startIndex, limit);
        return new SysResultLayui<User>(200,"OK",count,itemList);
    }
    /**添加用户信息*/
    @Override
    @Transactional  //开启事务的控制
    public void saveUsername(User user) {
        user.setStatus(1L);
        userMapper.insert(user);
    }
    /**修改用户信息*/
    @Override
    @Transactional  //开启事务的控制
    public void updateUsers(User user) {
        userMapper.updateById(user);
        System.out.println("更新："+userMapper.updateById(user));
    }
}
